package top.yueyazhui.account.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.yueyazhui.account.mapper.AccountMapper;
import top.yueyazhui.account.service.AccountService;

@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    AccountMapper accountMapper;

    @Override
    public boolean deductAccount(String userId, Double money) {
        Double balance = accountMapper.getMoneyByAccount(userId);
        if (balance < money) {
            throw new RuntimeException("余额不足");
        }
        accountMapper.updateAccount(userId, money);
        return true;
    }
}
